<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport"
			content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>AIT国际汽车改装展</title>
		<script src="./js/responsive.js" type="text/javascript" charset="utf-8"></script>
		<meta name='keywords' content='' />
		<meta name='description' content='' />
		<meta name="author" content="" />
		<link rel="stylesheet" type="text/css" href="./css/public.css?1.0.0" />
		<link rel="stylesheet" type="text/css" href="./css/swiper.min.css" />
		<link rel="stylesheet" type="text/css" href="./layer2/need/layer.css" />
		<script type="text/javascript">
			document.write('<link rel="stylesheet" type="text/css" href="./css/style.css?v=' + new Date().getTime() + '"/>');
		</script>
		<style>
			.error{
				padding-top:0.1rem;
				font-size: 0.24rem;
				color:#dd0117
			}
			.img{
				width:100%;
			}
			.swiper-pagination-bullet{
				width:6px;
				height:6px;
				background:rgba(0,0,0,0);
				border:1px solid #fff;
				opacity: 1;
			}
			.swiper-pagination-bullet-active{
				background:rgba(255,255,255,1);
			}
			.content .form{
				padding-top:0.3rem;
			}
		</style>
	</head>
	<body>
		<div class="main home">
			<div class="content" >
				<div class="swiper-container" id="swiper-container-banner">
					<div class="swiper-wrapper" >
						<div class="swiper-slide ">
							<div class="ellipsis"><img src="./icon/1_12.jpg" ></div>
						</div>
						<div class="swiper-slide ">
							<div class="ellipsis"><img src="./icon/banner1.jpg" ></div>
						</div>
					</div>
					<div class="swiper-pagination"></div>
				</div>
				
				<!-- <div class="top on">
					<p>2021中国国际汽车改装展览会</p>
					<h4>参观门票申请</h4>
				</div> -->
				<div class="form">
					<div class="con-lis">
						<div class="lis">
							<label class="lab">手机号</label>
							<div class="posit-fast">
								<input class="inp-lb" type="number" id="phone" name="phone" placeholder="请填写11位手机号" pattern="[0-9]*"
								oninput="if(value.length>11)value=value.slice(0,11)">
							</div>
							<div class="error hidden">手机号错误</div>
						</div>
						<div class="lis">
							<label class="lab">验证码</label>
							<div class="posit-fast">
								<input class="inp-lb" name="code" id="number" type="number" placeholder="请填写验证码" pattern="[0-9]*"
									oninput="if(value.length>6)value=value.slice(0,6)">
								<div class="code send">获取验证码</div>
							</div>
							<div class="error hidden">验证码错误</div>
						</div>
						<div class="lis">
							<button class="btn submit">下一步</button>
						</div>
					</div>
				</div>
				<img class="img" src="./icon/y_o1.jpg" >
				<div class="bot">
					<!-- <img src="./icon/1_04_03.jpg" > -->
					<h4>温馨提示</h4>
					<p>为了您的安全和健康，根据国务院联防联控机制要求和会展行业新冠肺炎防控指南，所有进入展馆的人员须提前实名制登记。请提交本人证件上的姓名、证件号与手机号进行登记。现场通过验证身份证原件、佩戴口罩、出示健康码、接受体温检测后才能进入展馆。</p>
				</div>
			</div>
		</div>
		<script src="./js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="./js/utils.js?v1.0.1" type="text/javascript" charset="utf-8"></script>
		<script src="./js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="./layer2/layer.js" type="text/javascript" charset="utf-8"></script>
		<script src="./js/request.js?v1.0.6" type="text/javascript" charset="utf-8"></script>
		<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js" type="text/javascript"></script>
		<script type="text/javascript" charset="utf-8">
			var leadid = getUrlParam('f');
			if(leadid){
				setCookie('leadid',leadid,1)
			}
			var id = getUrlParam('id');
			var code = getUrlParam('code');
			var openid = getCookie('openid');
			var firstonclick = true;
			var hostUrl = window.location.protocol+"//"+window.location.host;
			function replaceParamVal(paramName,replaceWith) {
				 var oUrl = this.location.href.toString();
				 var re=eval('/('+ paramName+'=)([^&]*)/gi');
				 var nUrl = oUrl.replace(re,paramName+'='+replaceWith);
				 this.location = nUrl;
				 window.location.href=nUrl
			}
			var browser = {
			    versions: function () {
			        var u = navigator.userAgent, app = navigator.appVersion;
			        return {         //移动终端浏览器版本信息
			            trident: u.indexOf('Trident') > -1, //IE内核
			            presto: u.indexOf('Presto') > -1, //opera内核
			            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
			            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
			            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
			            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
			            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
			            iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
			            iPad: u.indexOf('iPad') > -1, //是否iPad
			            webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
			        };
			    }(),
			    language: (navigator.browserLanguage || navigator.language).toLowerCase()
			}
			if (browser.versions.mobile) {//判断是否是移动设备打开。browser代码在下面
			        var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
			        if (ua.match(/MicroMessenger/i) == "micromessenger") {
			                //在微信中打开
							if(!openid && !code){
								getOpenId()
							}
							if(openid){
								apply()
							}
							getshare()
			        }
			        if (ua.match(/WeiBo/i) == "weibo") {
			                //在新浪微博客户端打开
			        }
			        if (ua.match(/QQ/i) == "qq") {
			                //在QQ空间打开
			        }
			        if (browser.versions.ios) {
			                //是否在IOS浏览器打开
							
			        } 
			        if(browser.versions.android){
			                //是否在安卓浏览器打开
			        }
			} else {
			        //否则就是PC浏览器打开
					console.log('pc')
			}
			// wx9300259ba702b2a1
			function getOpenId(){
				var local = window.location.href; // 获取页function 面url
				//没有微信用户信息，没有授权-->> 需要授权，跳转授权页面
				window.location.href =
					`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9300259ba702b2a1&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_base#wechat_redirect`;
			};
			if(code && !openid){
				getConfig() 
			}
			//是否报名
			function apply(){
				var params = {
					openId:openid
				}
				ajaxGet('apply/getApplyByOpenId',params, function(res) {
					if(res.code != 200){
						layer.open({
							content: res.msg,
							skin: 'msg',
							time: 2, //2秒后自动关闭
						});
						return false
					}
					if(res.data){
						setCookie('uid',res.data.id,1)
						if(res.data.idcard && res.data.name && res.data.qrcode){
							url = encodeURI('committed.html?f='+res.data.id+'&v='+new Date().getTime());
							location.replace(url)
						}
					}
					
				},
				function(err){
					
				})
			}
			//获取微信信息
			function getConfig(){
				var code = getUrlParam('code')
				var params = {
					code:code
				}
				ajaxGet('apply/getOpenId',params, function(res) {
					if(res.code != 200){
						layer.open({
							content: res.msg,
							skin: 'msg',
							time: 3, //2秒后自动关闭
						});
						return false
					}
					if(res.data && res.data.openid){
						replaceParamVal('code','')
						openid = res.data.openid
						setCookie('openid',res.data.openid,1)
						apply()
					}
				},
				function(err){
					
				})
			}
			
			function getshare() {
				var params = {
					url:window.location.href
				}
				ajaxGet('apply/getShareAccess',params, function(res) {
					if(res.code != 200){
						layer.open({
							content: res.msg,
							skin: 'msg',
							time: 3, //2秒后自动关闭
						});
						return false
					}
					if(res.data){
						wx.config({
							debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。   
							appId: res.data.appId, // 必填，公众号的唯一标识
							timestamp: res.data.timestamp, // 必填，生成签名的时间戳
							nonceStr: res.data.noncestr, // 必填，生成签名的随机串
							signature: res.data.signature, // 必填，签名，见附录1
							jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','hideMenuItems'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
						  });
						  wx.error(function (res) {
							//alert("失败："+res.msg);
						  });
						
						// wx.config 检测无误后，会进入到  ready 方法 。 注意type参数。微信多数的坐标体系都为gcj02
						  wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
							  wx.hideMenuItems({
									menuList:['menuItem:copyUrl',
										  'menuItem:openWithQQBrowser',
										  'menuItem:openWithSafari',
										  'menuItem:share:qq',
										  'menuItem:share:QZone',
										  'menuItem:share:weiboApp',
										  'menuItem:share:facebook'],
							  });
							wx.checkJsApi({
								jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
								success: function(res) {
									// 以键值对的形式返回，可用的api值true，不可用为false
									// 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
								}
							});
							//分享朋友圈
							wx.onMenuShareTimeline({
								title:'【点击报名】10月22-24日 AIT国际汽车改装展' , // 分享标题
								link: window.location.href, // 分享链接
								imgUrl: hostUrl + '/icon/logo.jpg', // 分享图标
								success: function () {
									// 用户确认分享后执行的回调函数
								},
								cancel: function () {
									// 用户取消分享后执行的回调函数
								}
							});
							 
							//分享朋友
							wx.onMenuShareAppMessage({
								title: '【点击报名】10月22-24日 AIT国际汽车改装展', // 分享标题
								desc: '东莞·广东现代国际展览中心', // 分享描述
								link: window.location.href, // 分享链接
								imgUrl: hostUrl + '/icon/logo.jpg', // 分享图标
								type: '', // 分享类型,music、video或link，不填默认为link
								dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
								success: function () {
									// 用户确认分享后执行的回调函数
								},
								cancel: function () {
									// 用户取消分享后执行的回调函数
								},
								fail:function(res){
									//alert(res);
								}
							});
						  });
					}
				},
				function(err){
					
				})
				
			}
			$('.submit').on('click',function(){
				var _phone = $('#phone').val();
				var _code = $('#number').val();
				if(!_phone || _phone.length != 11){
					error($('#phone'),'请填写11位手机号')
					return false
				}
				if(!checkPhone(_phone)){
					error($('#phone'),'请填写正确的手机号')
					return false
				}
				removerror($('#phone'))
				if(!_code || _code.length != 6){
					error($('#number'),'请填写验证码')
					return false
				}
				removerror($('#number'))
				var params ={
					phone:_phone,
					code:_code,
				}
				if(openid){
					params.openId = openid
				}
				if(!firstonclick){
					return false
				}
				firstonclick = false
				// url = encodeURI('form.html?phone='+_phone+'&f=10023&v='+new Date().getTime());
				// window.location = url;
				// return
				ajaxPost('apply/login',JSON.stringify(params), function(res) {
					firstonclick = true
					if(res.code != 200){
						layer.open({
							content: res.msg,
							skin: 'msg',
							time: 3, //2秒后自动关闭
						});
						return false
					}
					removerror($('#number'))
					if(res.data.id){
						setCookie('uid',res.data.id,1)
					}
					if(res.data.idcard){
						url = encodeURI('committed.html?f='+res.data.id+'&v='+new Date().getTime());
						window.location = url;
					}else{
						url = encodeURI('form.html?phone='+_phone+'&f='+res.data.id+'&v='+new Date().getTime());
						window.location = url;
					}
					
					
				},
				function(err){
					firstonclick = true
					if(err.responseJSON.code == '5000005' || err.responseJSON.code == '5000006' || err.responseJSON.code == '5000007'){
						error($('#number'),err.responseJSON.msg)
						return
					}
					layer.open({
						content: err.responseJSON.msg,
						skin: 'msg',
						time: 2, //2秒后自动关闭
					});
				})
				
			})
			function goBack() {
				window.history.go(-1)
			}
			//检查电话
			function checkPhone (val) {
				var pattern = /^1[3456789]\d{9}$/;
				return pattern.test(val);
			};
			// 获取验证码
			var countdown = 60;
			$(document).on('click', '.send', function() {
				var _phone = $('#phone').val();
				var obj = $('.send');
				if(!_phone || _phone.length != 11){
					error($('#phone'),'请填写11位手机号')
					return false
				}
				removerror($('#phone'))
				if(!checkPhone(_phone)){
					error($('#phone'),'请填写正确的手机号')
					return false
				}
				removerror($('#phone'))
				var params = {
					phone:_phone
				}
				ajaxGet('apply/sendSms',params, function(res) {
					settime(obj)
				},
				function(err){
					layer.open({
						content: err.responseJSON.msg,
						skin: 'msg',
						time: 3, //2秒后自动关闭
					});
				})
			});
			// 倒计时
			function settime(obj) { //发送验证码倒计时
				if (countdown == 0) {
					obj.addClass('send');
					obj.text("获取验证码");
					countdown = 60;
					return;
				} else {
					obj.removeClass('send');
					obj.text(countdown + "秒后可重发");
					countdown--;
				}
				setTimeout(function() {
					settime(obj)
				}, 1000)
			};
			//banner
			if($('.swiper-slide').length>1){
				var mySwiper = new Swiper('#swiper-container-banner', {
					pagination: '.swiper-pagination',
					slidesPerView: 1,
					observer:true,//修改swiper自己或子元素时，自动初始化swiper 
					observeParents:true,//修改swiper的父元素时，自动初始化swiper 
					paginationClickable: true,
					autoplayDisableOnInteraction : false,
					autoplay : 5000,
					loop: true,
					//autoHeight: true
				});
			}
			
		</script>
	</body>
</html>
